package com.ctshk.sapp.air.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.air.dto.AirProductInfoDTO;
import com.ctshk.rpc.air.dto.AirProductListDTO;
import com.ctshk.rpc.air.dto.OperationsCenterGetProductListDTO;
import com.ctshk.rpc.air.req.*;
import com.ctshk.rpc.air.service.IAirProductCostTouristService;
import com.ctshk.rpc.air.service.IAirProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 机票产品 前端控制器
 * </p>
 *
 * @author lihang
 * @since 2021-03-05
 */
@Api(value = "手动机票产品", tags = "手动机票产品")
@RestController
@RequestMapping("/air-product")
public class AirProductController extends BaseController {


    @DubboReference
    private IAirProductService iAirProductService;
    @DubboReference
    private IAirProductCostTouristService iAirProductCostTouristService;

    @ApiOperation(value = "新增手动机票产品", notes = "新增手动机票产品")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增手动机票产品", operDesc = "新增手动机票产品")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid AirProductDataReq req) {

        return iAirProductService.add(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "机票产品详情(资源中心)", notes = "机票产品详情(资源中心)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机票产品详情(资源中心)", operDesc = "机票产品详情(资源中心)")
    @PostMapping("/info/{id}")
    public Result<AirProductInfoDTO> info(@PathVariable @NotNull Long id) {

        return iAirProductService.info(id);
    }


    @ApiOperation(value = "机票产品详情(产品中心)", notes = "机票产品详情(产品中心)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机票产品详情(产品中心)", operDesc = "机票产品详情(产品中心)")
    @PostMapping("/info")
    public Result<AirProductInfoDTO> info(@RequestBody @NotNull AirStrategyDayInfoReq req) {

        return iAirProductService.info(req);
    }

    @ApiOperation(value = "机票产品列表", notes = "机票产品列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机票产品列表", operDesc = "机票产品列表")
    @PostMapping("/list")
    public Result<PageResponse<AirProductListDTO>> list(@RequestBody AirProductListReq req) {

        return iAirProductService.list(req);
    }

    @ApiOperation(value = "机票产品修改", notes = "机票产品修改")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机票产品修改(通过审批只能修改每日库存)", operDesc = "机票产品修改(通过审批只能修改每日库存)")
    @PostMapping("/edit")
    public Result edit(@RequestBody AirProductDataReq req) {

        return iAirProductService.edit(req, getCurrentUser(getRequest()));
    }


    @ApiOperation(value = "机票产品API设置", notes = "机票产品API设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机票产品API设置", operDesc = "机票产品API设置")
    @PostMapping("/edit/setapi")
    public Result editSetapi(@RequestBody @Valid List<AirProductApiReq> airProductApiReqs) {

        return iAirProductService.editSetapi(airProductApiReqs, getCurrentUser(getRequest()));
    }


    @ApiOperation(value = "机票产品状态设置(售卖,推荐,审批)", notes = "机票产品状态设置(售卖,推荐,审批)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机票产品售卖状态设置(售卖,推荐,审批)", operDesc = "机票产品售卖状态设置(售卖,推荐,审批)")
    @PostMapping("/edit/status")
    public Result editStatus(@RequestBody @Valid AirProductStatusReq req) {

        return iAirProductService.editStatus(req, getCurrentUser(getRequest()));
    }


//    @ApiOperation(value = "修改機票預訂信息", notes = "修改機票預訂信息")
//    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改機票預訂信息", operDesc = "修改機票預訂信息")
//    @PostMapping("/edit/settings")
//    public Result editSettings(@RequestBody @Valid AirProductReservationSettingsEditReq req){
//
//        return  iAirProductService.editSettings(req,getCurrentUser(getRequest()));
//    }

    @ApiOperation(value = "机票手动产品上架设置", notes = "机票手动产品上架设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "机票手动产品上架设置", operDesc = "机票手动产品上架设置")
    @PostMapping("/update/strategy")
    public Result updateStrategy(@RequestBody AirProductSaleStrategyUpdateReq req) {
        return iAirProductService.updateStrategy(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询机票手动产品上架设置", notes = "查询机票手动产品上架设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机票手动产品上架设置", operDesc = "机票手动产品上架设置")
    @PostMapping("/query/strategy/{id}")
    public Result updateStrategy(@PathVariable Long id) {
        return iAirProductService.queryStrategy(id);
    }


    @ApiOperation(value = "获取机票旅客类型", notes = "获取机票旅客类型")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "获取机票旅客类型", operDesc = "获取机票旅客类型")
    @PostMapping("/query/touristtype")
    public Result queryTouristType() {
        return iAirProductCostTouristService.queryTouristType();
    }

    /**
     * 获取产品列表 (内部接口)
     *
     * @param req
     * @return
     * @To 运营中心
     */
    @ApiOperation(value = "运营中心获取产品列表", notes = "运营中心获取产品列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "运营中心获取产品列表", operDesc = "运营中心获取产品列表")
    @PostMapping("/operationsCenterGetProductList")
    public Result<PageResponse<OperationsCenterGetProductListDTO>> operationsCenterGetProductList(@RequestBody AirProductOperationsCenterListReq req) {
        return iAirProductService.operationsCenterGetProductList(req);
    }

    /**
     * 产品审批
     *
     * @param req
     * @return
     */
    @ApiOperation(value = "机票产品审批", notes = "机票产品审批")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机票产品审批", operDesc = "机票产品审批")
    @PostMapping("/productExamine")
    public Result productExamine(@RequestBody AirProductExamineReq req) {
        return iAirProductService.productExamine(req, getCurrentUser(getRequest()));
    }
}


